<!--
	作者：939868405@qq.com
	时间：2018-10-11
	描述：文件签署列表
-->

<!--<template>-->
<template>
	<div class="m-view-goodsAccountBill2 m-window">
		<!--查询条件-->
		<div class="m-condition" v-if="diaShow">
			<el-row :gutter="10">
				<el-form
					:model="ruleForm"
					ref="ruleForm"
					label-width="70px"
					:inline-message="true"
					label-position="left"
				>
					<el-col :span="6">
						<el-form-item :label="accountType==4?'客户':'公司'" class="rightItem">
							<el-select
								v-model="CompanyCode"
								:placeholder="accountType==4?'请选择客户':'请选择公司'"
								value-key="id"
								@change="company_change"
								ref="content"
								:disabled="btnDis"
								filterable
								:clearable="accountType==4"
							>
								<el-option
									v-for="item in comOptions"
									:key="item.id"
									:label="item.companyName"
									:value="item.companyCode"
								></el-option>
							</el-select>
						</el-form-item>
					</el-col>
					<el-col :span="5">
						<el-form-item label="创建日期" class="rightItem">
							<el-date-picker
								v-model="applySDate"
								type="date"
								placeholder="开始日期"
								value-format="yyyy-MM-dd"
								:clearable="false"
								:editable="false"
								:picker-options="po1"
								:disabled="btnDis"
							></el-date-picker>
						</el-form-item>
					</el-col>
					<el-col :span="4">
						<el-date-picker
							v-model="applyEDate"
							type="date"
							placeholder="结束日期"
							value-format="yyyy-MM-dd"
							:clearable="false"
							:editable="false"
							:picker-options="po2"
							:disabled="btnDis"
						></el-date-picker>
					</el-col>
					<el-col :span="5">
						<el-form-item label="对账单号" class="rightItem">
							<el-input v-model="accountNo" placeholder="请输入单号" @keyup.enter.native="query" clearable></el-input>
						</el-form-item>
					</el-col>
					<el-col :span="4">
						<el-form-item label="签署模式" class="rightItem">
							<el-select
								v-model="signModel"
								placeholder="签署模式"
								value-key="value"
								@change="signState_change"
								:disabled="btnDis"
							>
								<el-option
									v-for="item in modelOptions"
									:key="item.value"
									:label="item.label"
									:value="item.value"
								></el-option>
							</el-select>
						</el-form-item>
					</el-col>
				</el-form>
			</el-row>
			<el-row :gutter="10">
				<el-form
					:model="ruleForm"
					ref="ruleForm"
					label-width="70px"
					:inline-message="true"
					label-position="left"
				>
					<el-col :span="6" v-if="sel_Supplier_show">
						<el-form-item label="供应商" class="rightItem">
							<el-input
								placeholder="请选择供应商"
								v-model="SupplierName"
								readonly
								clearable
								@focus="showSupplierDialog"
								@mouseenter.native="mouseEnter"
								@mouseleave.native="mounseLeave"
								:disabled="btnDis"
							>
								<el-button slot="append" icon="el-icon-search" @click="showSupplierDialog"></el-button>
								<span slot="suffix" @click="inputClearSon" class="m-cleanInput" v-show="inputClearBut">
									<i class="el-input_icon el-icon-circle-close el-input__clear"></i>
								</span>
							</el-input>
						</el-form-item>
					</el-col>
					<el-col :span="sel_Supplier_show?5:6">
						<el-form-item label="签署状态" class="rightItem">
							<el-select
								v-model="signState"
								placeholder="签署状态"
								value-key="value"
								@change="signState_change"
								:disabled="btnDis"
							>
								<el-option
									v-for="item in recOptions"
									:key="item.value"
									:label="item.label"
									:value="item.value"
								></el-option>
							</el-select>
						</el-form-item>
					</el-col>
				</el-form>
				<el-col :span="2" v-if="isHasChecked" class="m-floatright">
					<el-button type="primary" @click="totalDownload" :disabled="btnDis">批量下载</el-button>
				</el-col>
				<el-col :span="3" class="m-floatright">
					<el-button type="primary" @click="checkSteps" :disabled="btnDis">查看流程信息</el-button>
				</el-col>
				<el-col :span="2" class="m-floatright" v-if="signModel==1&&signState==1&&accountType==1">
					<el-button type="primary" @click="uploadAccount" :disabled="btnDis">上传附件</el-button>
				</el-col>
                <el-col :span="2" class="m-floatright" v-if="signModel==1&&signState==3&&accountType==1">
					<el-button type="primary" @click="uploadAccount" :disabled="btnDis">更新附件</el-button>
				</el-col>
				<el-col :span="2" class="m-floatright" v-if="signModel==1&&signState==3||signModel==0">
					<el-button type="primary" @click="edit" :disabled="btnDis">浏览</el-button>
				</el-col>
				<el-col :span="2" class="m-floatright">
					<el-button type="primary" @click="query" :disabled="btnDis">查询</el-button>
				</el-col>
			</el-row>
		</div>
		<!--签署文件列表-->
		<div class="m-agTable m-top2 m-bottom" v-if="diaShow">
			<ag-grid-component
				ref="agGridComponent"
				:getColumnDefs="columnDefs"
				:getRowSelection="'multiple'"
				:tableName="'filesSignList'"
				:getGridOptions="gridOptions"
				:getRowData="rowData"
				:isColFit="true"
				:systemInfo="$systemInfo"
				v-loading="loading"
			></ag-grid-component>
		</div>
		<div class="m-page" v-if="diaShow">
			<el-pagination
				@size-change="handleSizeChange"
				@current-change="handleCurrentChange"
				@prev-click="handlePrevClick"
				@next-click="handleNextClick"
				:current-page.sync="currentPage"
				:page-sizes="[30,50,100,150,200]"
				:page-size="pageSize"
				layout="total, sizes, prev, pager, next, jumper"
				:total="total"
			></el-pagination>
		</div>
		<!--签署文件浏览-->
		<div class="m-window" v-if="fileSignInfo_show">
			<fileSignInfo
				@cancelComponents="cancelComponents"
				:fileSignIn="fileSignIn"
				:removeTab="removeTab"
			></fileSignInfo>
		</div>
		<!--供应商信息-->
		<el-dialog
			title="供应商信息"
			:visible.sync="srmSupplierDialogVisible"
			width="50%"
			:before-close="srmSupplierDialogClose"
			v-dialogDrag
			:close-on-click-modal="false"
			:close-on-press-escape="false"
		>
			<srmSupplierInfo ref="srmSupplierInfo" :layout="layout" @setSrmSupplierInfo="setSrmSupplierInfo"></srmSupplierInfo>
			<!--@setSapSupplierCompanyInfo="getSelectedCompany" :setSelectedSupplierCode="getSelectedSupplierCode"-->
		</el-dialog>

		<!-- 查看流程信息弹窗 -->
		<accountSteps
			:dialogTitle="'会计对账流程信息'"
			:stepsVisible="stepsVisible"
			:stepsData="stepsData"
			:activeIndex="activeIndex"
			@dialogclose="closeSteps"
		></accountSteps>
		<!-- 上传附件弹窗 -->
		<el-dialog
			title="上传对账函"
			:visible.sync="uploadVisible"
			v-if="uploadVisible"
			width="500px"
			:before-close="closeUpload"
			v-dialogDrag
			:close-on-click-modal="false"
			:close-on-press-escape="false"
		>
			<lessoUploader
				:baseUrl="baseUrl"
				:userInfo="userInfo"
				:deleteBtn="true"
				@fileAdded="fileAdded"
				@fileRemoved="fileRemoved"
				@fileSuccess="fileSuccess"
				@fileError="fileError"
				@fileExceed="fileExceed"
				@overSize="overSizeHandler"
				@invalidFileType="onInvalidFile"
				:multiple="true"
				:limits="1"
				:allowDuplicateUploads="false"
				@deleteFile="onFileDelete"
				accept=".pdf, image/png, image/jpeg"
			></lessoUploader>
			<div class="el-upload__tip">只能上传.pdf, image/png, image/jpeg文件，且不超过20MB</div>
			<span slot="footer" class="dialog-footer">
				<el-button @click="closeUpload">取消</el-button>
				<el-button @click="completSign" type="primary">保存</el-button>
			</span>
		</el-dialog>
	</div>
</template>

<!--<script>-->
<script>
import _Api from "@/api";
import localeText from "@/i18n/agGridText";
import fileSignInfo from "@/views/accountManagement/fileSignInfo.vue";
import srmSupplierInfo from "@/components/srmSupplierInfo.vue";
import accountSteps from "@/components/accountSteps.vue";
import constant from "@/public/constant";
import serviceTime from "@/public/serverTime.js";
import gridOptions from 'lesso-common/public/gridOptions';
import Msg from "@/public/message.js";
import lessoUploader from 'lesso-file-upload/lessoUploader';
import apienv from '@/api/env';
import downLoadFileFunc from "@/public/downLoadFile"

export default {
	data () {
		return {
			ruleForm: {},
			btnDis: true,
			currentPage: 1,
			pageSize: 30,
			total: 0,
			current: 0,
			accountNo: "",//会计对账单号
			signState: 1,//签署状态
			recOptions: [
				{ value: 1, label: "未进行" },
				{ value: 2, label: "进行中" },
				{ value: 3, label: "已完成" }],
			applySDate: "",//开始日期
			applyEDate: "",//结束日期
			CompanyCode: "",//公司选项
			comOptions: [],
			SupplierCode: "",//供应商选项
			SupplierOptions: [],
			sel_Supplier_show: true,
			btn_sign_Dis: false,//签署按钮
			rowData: [],//行
			columnDefs: [],//列
			loading: false,//加载
			diaShow: true,
			fileSignInfo_show: false,
			fileSignIn: {},
			layout: {},
			srmSupplierDialogVisible: false,
			inputClearBut: false,
			SupplierName: "",
			//弹出框-签署预览
			po1: {
				disabledDate: this.disabledDate1
			},
			po2: {
				disabledDate: this.disabledDate2
			},

			//查看流程相关修改
			stepsVisible: false,
			// 当前流程数据
			stepsData: [],
			// 步骤进行到哪一步
			activeIndex: 0,

			//批量下载按钮控制
			isHasChecked: false,

			//控制颜色改变
			colorChange: false,
			// 签署模式
			signModel: 0,
			// 签署模式下拉选择内容
			modelOptions: [
				{ value: 0, label: "线上" },
				{ value: 1, label: "线下" },
			],
			//  上传附件弹窗
			uploadVisible: false,
			upload_url: this.$uploadUrl,
			//   文件上传地址
			baseUrl: apienv[constant.appenv].srm + 'uploadFastdfs/',
			//   用户信息
			userInfo: {
				userName: this.$global.user.employeeName,
				userId: this.$global.user.id,
				groupName: 'SRM'
			},
			//  文件集合  
			template: [],
			// 对账单id  
			accountId: '',
			//  用户类型
			accountType: ''
		}
	},
	created () {
		//默认供应商和公司的选项
		if (constant.accountType == 4) {
			this.sel_Supplier_show = false;
		}
		else {
			this.sel_Supplier_show = true;
		}
		this.accountType = constant.accountType
	},
	beforeMount () {
		this.gridOptions = Object.assign({
			context: {
				componentParent: this
			},
			// rowSelection: "single",
			animateRows: true, //排序动画
			enableFilter: true, //列过滤器
			enableSorting: true, //列排序
			enableCellChangeFlash: true,
			enableRangeSelection: true,
			enableColResize: true,
			localeText: localeText,
		}, gridOptions())

		this.columnDefs = [
			{ headerName: "id", field: "id", hide: true },
			{ headerName: "docId", field: "签署文件id", hide: true },
			{ headerName: "会计对账单号", field: "accountNo", width: 160, checkboxSelection: true, headerCheckboxSelection: true, headerCheckboxSelectionFilteredOnly: true },
			{ headerName: "公司", field: "companyName", width: 180, tooltipField: 'companyName' },
			{ headerName: "供应商", field: "supplierName", width: 190, tooltipField: 'supplierName' },
			{ headerName: "期初", field: "sapOpenBalance", width: 100, hide: true },
			{ headerName: "应付", field: "sapDebitSum", width: 100, hide: true },
			{ headerName: "已付", field: "sapLendSum", width: 100, hide: true },
			{ headerName: "余额", field: "sapBalance", width: 100, hide: true },
			{ headerName: "采购员", field: "buyer", width: 100 },
			{ headerName: "合同编号", field: "contractNo", width: 130 },
			{ headerName: "不符描述", field: "unConMemo", width: 160, tooltipField: 'unConMemo' },
			{ headerName: "申请人", field: "creator", width: 80, hide: true },
			{
				headerName: "签署状态",
				field: "signState",
				width: 100,
				cellRenderer: function (params) {
					const { curSigner } = params.data
					if (params.value == "1") {
						return '<span class="ag-icon">未进行</span>';
					} else if (params.value == "2") {
						if (curSigner == 1) {
							return '<span class="ag-icon">待联塑签署</span>';
						} else if (curSigner == 2) {
							return '<span class="ag-icon">待供应商签署</span>';
						} else {
							return '<span class="ag-icon">进行中</span>';
						}
					} else {
						return '<span class="ag-icon">已完成</span>';
					}
				}
			},
			{ headerName: "对账日期", field: "createDate", width: 90 },
			{ headerName: "截止日期", field: "endDate", width: 90 },
			{ headerName: "确认人", field: "confirmer", width: 90 },
            { headerName: "确认时间", field: "confirmDate", width: 90 },
            { headerName: "确认意见", field: "confirmMemo", width: 120,tooltipField: 'confirmMemo' },
			{ headerName: "审批人", field: "auditor", width: 90 },
			{ headerName: "审批时间", field: "auditDate", width: 90 },

			{ headerName: "公司电子签帐号", field: "ceSignAccount", width: 100, hide: true },
			{ headerName: "供应商电子签帐号", field: "seSignAccount", width: 100, hide: true },
			{ headerName: "签署文件地址", field: "url", width: 100, hide: true }
		];
	},
	mounted () {
		//默认日期范围 三个月
		var that = this;
		serviceTime.getServiceTime().then((serviceTime) => {
			if (serviceTime) {
				var resultDate;
				var year = serviceTime.getFullYear();
				var month = serviceTime.getMonth() + 1;
				var month2;
				var dataArr = [];
				dataArr.push(serviceTime.Format("yyyy-MM"));
				var day = 0;
				for (var i = 0; i < 2; i++) {
					switch (month) {
						case 1:
							year--;
							month += 11;
							break;
						default:
							month--;
							break;
					}
					month2 = month;
					month2 = (month2 < 10) ? ('0' + month2) : month2;
					resultDate = year + '-' + month2;
					dataArr.push(resultDate);
				}
				for (let i in dataArr) {
					var data = dataArr[i].split('-');
					day += new Date(data[0], data[1], 0).getDate();
				}
				that.applySDate = new Date(serviceTime.getTime() - 3600 * 1000 * 24 * day).Format('yyyy-MM-dd');
			}
			that.applyEDate = serviceTime.Format("yyyy-MM-dd");
		})
		this.getAuthInfo();

	},
	components: {
		fileSignInfo,
		srmSupplierInfo,
		accountSteps,
		lessoUploader
	},
	methods: {
		// 下载对账函
		downLoadFile (params) {
			var obj = {};
			obj.viewPath = params.url;
			obj.groupName = 'TEST';
			obj.fileName = ''
			if (params.url.indexOf('SRM') > -1) {
				obj.groupName = 'SRM'
			} else if (params.url.indexOf('SIGN') > -1) {
				obj.groupName = 'SIGN'
			} else if (params.url.indexOf('TEST') > -1) {
				obj.groupName = 'TEST'
			}
			downLoadFileFunc(obj, '对账函.png')
		},
		disabledDate1 (time) {
			if (this.applyEDate)
				return time.getTime() > new Date(this.applyEDate).getTime();
		},
		disabledDate2 (time) {
			if (this.applySDate)
				return time.getTime() < (new Date(this.applySDate).getTime() - 3600 * 1000 * 24);
		},
		handleSizeChange (params) {
			this.pageSize = params;
			this.currentPage = 1;
			this.search();
		},
		handleCurrentChange (params) {
			if (this.current === 1) {
				this.currentPage = 1;
			} else {
				this.currentPage = params;
			}
			this.search();
		},
		query(){
			this.currentPage = 1;
			this.search();
		},
		handlePrevClick (params) {
			this.currentPage = params;
			this.handleCurrentChange(this.currentPage);
		},
		handleNextClick (params) {
			this.currentPage = params;
			this.handleCurrentChange(this.currentPage);
		},
		mounseLeave () {
			if (this.SupplierName != "")
				this.inputClearBut = false;
		},
		mouseEnter () {
			if (this.SupplierName != "")
				this.inputClearBut = true;
		},
		inputClearSon () {
			this.SupplierCode = "";
			this.SupplierName = "";
			this.inputClearBut = false;
		},
		setSrmSupplierInfo (msg) {
			if (msg.length > 0) {
				this.srmSupplierDialogVisible = false;
				this.SupplierCode = msg[0].supplierCode;
				this.SupplierName = msg[0].supplierName;
				// this.inputClearBut = true;
			}
		},
		srmSupplierDialogClose (done) {
			done();
		},
		search () {
			var obj = {
				eqParams: {},//=
				likeParams: {},//like
				geParams: {},//>=
				leParams: {}//<=
			};
			//会计对账单号
			if (this.accountNo.replace(/\s+/g, ""))
				obj.likeParams.accountNo = this.accountNo.replace(/\s+/g, "");//会计对账单号
			//开始日期	
			if (this.applySDate)
				obj.geParams.begin_date = this.applySDate;
			//结束日期	
			if (this.applyEDate)
				obj.leParams.end_date = this.applyEDate;
			//签署状态	
			obj.eqParams.signState = this.signState;
			//公司
			if (this.CompanyCode) {
				obj.eqParams.companyCode = this.CompanyCode;
			} else {
				if (this.accountType == 1) {
					Msg.showPopMsg('请先选择公司!')
					return
				}
			}
			//供应商	
			if (this.SupplierCode)
				obj.eqParams.supplierCode = this.SupplierCode;
			//				obj.current = this.current;
			// if (this.accountNo) {
			// 	this.currentPage = 1;
			// }
			obj.size = this.pageSize;
			obj.current = this.currentPage;
			obj.eqParams.signMode = this.signModel
			var that = this;
			this.loading = true;
			this.btnDis = true;
			// that.$refs["agGridComponent"].gridOptions.api.setColumnDefs(that.columnDefs)
			_Api.SignList(obj).then(function (response) {
				that.current = 0;
				that.btnDis = false;
				var data = response.data;
				that.loading = false;
				if (data.code == "1") {
					if (data.total > 0) {
						that.$refs["agGridComponent"].gridOptions.api.setRowData(data.rows);
						that.total = data.total;
					} else {
						that.$refs["agGridComponent"].gridOptions.api.setRowData([]);
						that.total = 0;
					}
				}
				else {
					Msg.showErrorMsg(data.info);
					that.total = 0;
					that.current = 1;
				}
			}).catch((err) => {
				Msg.showErrorMsg(err.data.message);
				that.loading = false;
				that.btnDis = false;
			})
		},
		edit (node) {
			var row = this.$refs["agGridComponent"].gridOptions.api.getSelectedRows();
			if (row.length <= 0) {
				Msg.showPopMsg("提示：请选择一张想浏览的会计对账单！")
				return;
			}
			else if (row.length > 1) {
				Msg.showPopMsg("提示：每次只能选择一张想浏览的会计对账单！")
				return;
			}
			else {
				this.fileSignIn = row[0];
				this.fileSignInfo_show = true;
				this.diaShow = false;
			}

		},
		cancelComponents (msg) {
			if (msg) {
				this.fileSignInfo_show = false;
				this.diaShow = true;
				//					if(this.selCompanyCode){
				this.search();
				//					}
			}
		},
		sign () {

		},
		signState_change () {
			this.currentPage = 1;
			this.search();
		},
		company_change (value) {
			if (value) {
				// var obj = {
				// 	name:value.companyCode
				// };
				// var that = this;
				this.layout.companyCode = value;
				this.layout.auth = true;
				//					_Api.getAuthSupplierByCompanyCode(obj).then(function(response){
				//						var data = response.data;
				//						if(data.code == "1"){
				//							if(data.total > 0)
				//								that.SupplierOptions = data.rows;
				//							else
				//								that.SupplierOptions = [];
				//						}
				//					}).catch(()=>{
				//						that.$alert("操作失败！" ,{
				//							showClose:false,
				//							confirmButton:"确定",
				//							customClass:"alertFailure"
				//						});
				//						that.SupplierOptions = [];
				//					})
			} else {
				this.layout = {};
				// this.getAuthInfo();
			}
		},
		getAuthInfo () {
			//获取当前账号权限公司
			var obj = {};
			//帐号类型：4为供应商
			if (this.$global.user.userTypeId == 4) {
				obj.account = this.$global.user.userName;
				obj.userType = 2;
			}
			//帐号类型：1为应付人员
			else if (this.$global.user.userTypeId == 1) {
				obj.account = this.$global.user.oaNum;
				obj.userType = 1;
			}
			var that = this;
			_Api.getAuthInfo(obj).then(function (response) {
				var data = response.data;
				if (data.code == "1") {
					that.btnDis = false;
					//绑定公司和供应商的选项
					if (data.rows.myMstCompany)
						that.comOptions = data.rows.myMstCompany;
					if (data.rows.myMstSupplier)
						that.SupplierOptions = data.rows.myMstSupplier;

					//默认供应商和公司的选项
					if (that.$global.user.userTypeId == 4) {
						//that.sel_Supplier_show = false;
						that.SupplierCode = data.rows.myMstSupplier[0].supplierCode;
					}
					else {
						//that.sel_Supplier_show = true;
					}
					that.CompanyCode = that.comOptions[0].companyCode
					that.layout.companyCode = that.CompanyCode
					that.layout.auth = true
					that.search();
				} else {
					that.comOptions = [];
					that.SupplierOptions = [];
				}
			}).catch((err) => {
				Msg.showErrorMsg(err.data.message);
				that.comOptions = [];
				that.SupplierOptions = [];
			})
		},
		showSupplierDialog () {
			var that = this;
			if (!this.layout.companyCode) {
				Msg.showPopMsg("提示：请选择公司！")
				this.$refs.content.focus();
				return;
			} else {
				this.srmSupplierDialogVisible = true;
				this.$nextTick(_ => {
					that.$refs.srmSupplierInfo.search();
				});

				// 	setTimeout(()=>{
				// 	that.$refs.srmSupplierInfo.search();
				// },50)
			}
		},

		checkSteps () {
			var that = this;
			this.stepsData = [];
			var row = this.$refs["agGridComponent"].gridOptions.api.getSelectedRows();
			if (row.length > 1) {
				Msg.showPopMsg("提示：不能同时查询多张会计对账单的流程！")
				return;
			} else if (row.length == 0) {
				Msg.showPopMsg("提示：请选择需要查看流程的会计对账单！")
				return;
			}
			var obj = {
				id: row[0].id
			}

			_Api.getAccountBillProcess(obj).then(function (response) {
				var data = response.data;
				if (data.code == 1) {
					if (data.rows.length > 0) {
						data.rows.forEach((item, index) => {
							if (item.processName == '签署') {
								var nameHandle = '';
								var nameHandleOther = '';
								if (item.signState == 2) {
									if (item.curSigner == 1) {
										nameHandle = '供应商已签署'
										nameHandleOther = '联塑未签署'
									} else if (item.curSigner == 2) {
										nameHandle = '联塑已签署'
										nameHandleOther = '供应商未签署'
									}
								} else if (item.signState == 3) {
									if (item.curSigner == 1) {
										nameHandle = '联塑已签署'
										nameHandleOther = '供应商已签署'
									} else if (item.curSigner == 2) {
										nameHandle = '供应商已签署'
										nameHandleOther = '联塑已签署'
									}
								}
								var step = {
									name: item.processName,
									prcsDate: item.signFirstDate,
									prcsDateOther: item.signComDate,
									result: item.processStatus,
									prcsUser: nameHandle,
									prcsUserOther: nameHandleOther
								}
							} else {
								var step = {
									name: item.processName,
									prcsDate: item.handleDate,
									result: item.processStatus
								}
							}

							if (item.processStatus === 2) {
								that.activeIndex = index + 1;
							}
							that.stepsData.push(step);
						})
					} else {
						Msg.showErrorMsg(data.info);
						return;
					}
				}
			})
			this.stepsVisible = true
		},

		closeSteps () {
			this.stepsVisible = false
		},
		// 批量下载
		totalDownload () {
			var obj = [];
			var tempStr = '';
			var tempNo = 0;
			var that = this;
			this.btnDis = true;
			var rowTotal = this.$refs["agGridComponent"].gridOptions.api.getSelectedRows();
			// setTimeout(function(){

			// },3000);
			rowTotal.forEach(item => {
				if (item.url == '') {
					tempNo = tempNo + 1;
					if (tempNo == 1) {
						tempStr = item.accountNo;
					} else {
						tempStr = tempStr + '，' + item.accountNo;
					}
				} else {
					let objMx = {
						accountNo: item.accountNo,
						supplierName: item.supplierName,
						fileResult: {
							groupName: '',
							viewPath: item.url
						}
					}
					if (constant.appenv == 'app') {
						if (this.signModel == 1) {
							objMx.fileResult.groupName = 'SRM'
						} else {
							objMx.fileResult.groupName = 'SIGN'
						}
					} else {
						objMx.fileResult.groupName = 'SRM'
					}
					//配置下载参数
					obj.push(objMx);
				}
			})
			if (tempNo != 0) {
				that.btnDis = false;
				Msg.showErrorMsg(tempStr + ';' + '以上会计对账单没有对应文件，无法下载！');
				return;
			}

			_Api.totalDownload(obj).then(function (response) {
				that.btnDis = false;
				var data = response.data;
				if (that.$global.user.userTypeId == 4) {
					that.downLoad(constant.employeeName + '.zip', data);
				} else if (that.$global.user.userTypeId == 1) {
					that.downLoad(constant.butxt + '.zip', data);
				}
			}).catch(err => {
				that.btnDis = false;
				Msg.showErrorMsg(err.data.message);
				return;
			})
		},
		// a标签下载文件
		downLoad (filename, url) {
			let blob = new Blob([url], {
				type: 'application/octet-stream'
			})
			let blobURL = window.URL.createObjectURL(blob);
			var eleLink = document.createElement('a');
			eleLink.style.display = 'none';
			// eleLink.setAttribute("href", url);   //文件下载地址
			eleLink.setAttribute("href", blobURL);   //文件下载地址
			eleLink.setAttribute("download", filename);  //download属性只能在同域实现
			// 触发点击
			document.body.appendChild(eleLink);
			eleLink.click();
			// 然后移除
			document.body.removeChild(eleLink);
		},
		// 点击上传附件
		uploadAccount () {
			var row = this.$refs["agGridComponent"].gridOptions.api.getSelectedRows();
			if (row.length > 1) {
				Msg.showPopMsg("提示：不能同时上传多张会计对账单的对账函！")
				return;
			} else if (row.length == 0) {
				Msg.showPopMsg("提示：请选择需要上传的会计对账单！")
				return;
			}
			this.accountId = row[0].id
			this.uploadVisible = true
		},
		// 关闭上传附件弹窗
		closeUpload () {
			//   this.$refs['upload'].clearFiles()
			this.uploadVisible = false
		},
		// 完成签署
		completSign () {
			if (this.template.length == 0) {
				Msg.showPopMsg("请先选择需要上传的附件！")
				return
			}
			let obj = {
				signState: 3,
				id: this.accountId,
				modifyerId: this.$global.user.id,
				modifyer: this.$global.user.employeeName,
				url: this.template[0].url,
				curSigner: this.$global.user.userTypeId == 4 ? 1 : 2
			}
			this.$http.signCompleted(obj).then(({ data }) => {
				if (data.code == 1) {
					Msg.showSuccessMsg('签署完成')
					this.closeUpload()
					this.search()
				} else {
					Msg.showErrorMsg(data.info)
				}
			}).catch(err => {
				Msg.showErrorMsg(err.data.message)
			})
		},
		// 文件通过检查回调
		fileAdded (file) {
			//   this.isFiles = false
		},
		// 文件已移除回调
		fileRemoved (file, res) {
			if (res.code == 200) {
				this.template.forEach((ele, index) => {
					if (ele.md5 == file.md5) {
						this.template.splice(index, 1)
					}
				});
			}
		},
		// 文件上传成功回调
		fileSuccess (file, message) {
			this.template = []
			const { size, viewPath, name, md5 } = file
			this.template.push({
				size,
				url: viewPath,
				name,
				md5,
				creator: this.$global.user.loginName,
				creatorId: this.$global.user.id,
			})
		},
		// 删除文件
		onFileDelete (file, callback) {
			this.$confirm("是否删除该附件？", "消息提示", {
				confirmButtonText: "确定",
				cancelButtonText: "取消",
				distinguishCancelAndClose: true
			}).then(() => {
				callback(true)
			}).catch(() => {
				this.$message({
					message: '已取消删除',
					type: 'info'
				})
			})
		},
		// 文件超出大小回调
		overSizeHandler (file) { // 文件过大回调
			this.$message.warning("选择的文件大小不能超过20M")
		},
		//文件类型不合法
		onInvalidFile (file) {
			this.$message.warning('只能上传.pdf/image/png/image/jpeg类型文件')
		},
		// 文件上传失败回调
		fileError (file, message, chunk) {
			message = JSON.parse(message)
			this.$message.error(message.msg);
		},
		//文件个数超出限制
		fileExceed (files, fileList) {
			this.$message.warning('上传文件个数超出限制,最多只能上传1个文件')
		},
		// 点击已上传文件回调
		handlePreview (file) {
			//console.log(file);
		},
		// 删除文件回调
		handleRemove (file, fileList) {
		},
		// 删除文件前回调
		beforeRemove (file, fileList) {
			// return this.$confirm(`确定移除 ${ file.name }？`).catch(()=>{});
		},
		// 文件状态改变回调
		fileChange (file, fileList) {
			this.isFiles = false
		},
		// 文件超出上传个数
		handleExceed (files, fileList) {
			this.$message({
				message: '文件超出个数！',
				type: 'warning'
			});
		},
		// 文件上传成功
		uploadSuccess (res, file, fileList) {
			if (res.code == 1) {
				this.template = []
				const { fileName, orgName } = res.rows[0]
				this.template.push({
					size: file.size,
					url: fileName,
					name: orgName,
					creator: this.$global.user.loginName,
					creatorId: this.$global.user.id,
				})
			}
		},
		// 文件上传前
		beforeAvatarUpload (file) {
			let fileType = file.name.substring(file.name.lastIndexOf('.') + 1).toLocaleLowerCase()
			if (fileType != "png" && fileType != "pdf" && fileType != "jpg") {
				this.$message({
					message: '上传文件类型只支持.pdf/.jpg/.png！',
					type: 'warning'
				});
				return false;
			}
			const size = file.size / 1024 / 1024 < 20;
			if (!size) {
				this.$message({
					message: '上传模板大小不能超过 20MB!',
					type: 'warning'
				});
				return false;
			}
		},
	},
	props: {
		removeTab: {
			type: Function
		}
	},
	watch: {
		accountNo (val) {
		},
		CompanyCode () {
			this.current = 1;
			this.search();
		},
		applySDate (value) {
			if (value == null)
				this.applySDate = ""
			this.current = 1;
		},
		applyEDate (value) {
			if (value == null)
				this.applyEDate = ""
			this.current = 1;
		},
		SupplierName () {
			this.current = 1;
			this.search();
		},
		signState () {
			this.current = 1;
			if (this.signState === 3) {
				this.isHasChecked = true;
			} else {
				this.isHasChecked = false;
			}
		}
	}
}
</script>
